package com.huaxin.hxfiles.config;

import com.huaxin.hxfiles.service.FileUploadService;
import com.huaxin.hxfiles.service.impl.LocalFileUploader;
import com.huaxin.hxfiles.service.impl.MinioUploader;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
/**
 * 文件上传服务类
 *
 * @author
 * @date 2025/04/01
 */
@Configuration
public class UploadServiceConfig {

    private final MinioClient minioClient;
    private final MinioConfig minioConfig;

    @Autowired
    public UploadServiceConfig(MinioClient minioClient, MinioConfig minioConfig) {
        this.minioClient = minioClient;
        this.minioConfig = minioConfig;
    }

    @Bean
    @Primary
    @ConditionalOnProperty(name = "upload.type", havingValue = "minio")
    public FileUploadService minioUploader() {
        return new MinioUploader(minioClient, minioConfig);
    }


    @Bean
    @ConditionalOnProperty(name = "upload.type", havingValue = "local")
    public FileUploadService localUploader() {
        return new LocalFileUploader();
    }
}